<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
	<link rel="stylesheet" href="">
</head>
<body>
	<script>
		// str是要去除空格的字符串
		var str = '  as ddd ee 4kkk ,mm  ';
		// 去除str所有的空格
		var str1 = str.replace(/\s*/g,"");
		console.log(str1);
		// 去除str两头的空格
		var str2 = str.replace(/^\s*|\s*$/g,"");
		console.log(str2);
		// 去除左空格
		var str3 = str.replace(/^\s*/,"");
		console.log(str3);
		// 去除右空格
		var str4 = str.replace(/(\s*$)/g,"");
		console.log(str4);
	</script>
</body>
</html>